CREATE TABLE [dbo].[TDREPO_DETA]
(
[CO_EMPR] [dbo].[TD_VC_002] NOT NULL,
[NU_ANNO] [dbo].[TD_IN_004_ANNO] NOT NULL CONSTRAINT [DF__TDREPO_DE__NU_AN__06CD04F7] DEFAULT (datepart(year,getdate())),
[CO_REPO] [dbo].[TD_VC_003] NOT NULL,
[CO_TITU] [dbo].[TD_VC_003] NOT NULL,
[CO_SUBT] [dbo].[TD_VC_003] NOT NULL,
[CO_CNTA_EMPR] [dbo].[TD_VC_020_CNTA] NOT NULL,
[NU_SECU] [dbo].[TD_IN_001] NOT NULL,
[ST_AUXI] [dbo].[TD_VC_001] NOT NULL,
[ST_ORDE] [dbo].[TD_VC_001] NOT NULL,
[ST_OPER] [dbo].[TD_VC_003] NOT NULL,
[TI_AUXI_EMPR] [dbo].[TD_VC_001] NULL,
[CO_AUXI_EMPR] [dbo].[TD_VC_020] NULL,
[CO_ORDE_SERV] [dbo].[TD_VC_020] NULL,
[CO_USUA_CREA] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_CREA] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TDREPO_DE__FE_US__09A971A2] DEFAULT (getdate()),
[CO_USUA_MODI] [dbo].[TD_VC_008_USUA] NOT NULL,
[FE_USUA_MODI] [dbo].[TD_DT_001_SIST] NOT NULL CONSTRAINT [DF__TDREPO_DE__FE_US__0A9D95DB] DEFAULT (getdate())
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TDREPO_DETA] ADD CONSTRAINT [CK__TDREPO_DE__CO_CN__08B54D69] CHECK (([CO_CNTA_EMPR]>='0' AND [CO_CNTA_EMPR]<='99999999999999999999'))
GO
ALTER TABLE [dbo].[TDREPO_DETA] ADD CONSTRAINT [CK__TDREPO_DE__NU_AN__07C12930] CHECK (([NU_ANNO]>=(0)))
GO
ALTER TABLE [dbo].[TDREPO_DETA] ADD CONSTRAINT [XPKTDREPO_DETA] PRIMARY KEY CLUSTERED  ([CO_EMPR], [NU_ANNO], [CO_REPO], [CO_TITU], [CO_SUBT], [CO_CNTA_EMPR], [NU_SECU]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[TDREPO_DETA] ADD CONSTRAINT [FK1_TDREPO_CNTA_A_TDREPO_CNTA_DETA] FOREIGN KEY ([CO_EMPR], [NU_ANNO], [CO_REPO], [CO_TITU], [CO_SUBT], [CO_CNTA_EMPR]) REFERENCES [dbo].[TDREPO_CNTA] ([CO_EMPR], [NU_ANNO], [CO_REPO], [CO_TITU], [CO_SUBT], [CO_CNTA_EMPR])
GO
